/**
 * Created with IntelliJ IDEA.
 * Description:二叉树的实现
 * User: LXW
 * Date: 2022-02-24
 * Time: 19:05
 */
class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode(int val) {
        this.val = val;
    }
}
public class BinaryTree {
    /*
    这种方式是以穷举的方式创建二叉树的，并不好，初期可以先以这种方式进行创建，但并不是正确的创建方式
     */
    public static TreeNode creative() {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2= new TreeNode(2);
        TreeNode treeNode3= new TreeNode(3);
        TreeNode treeNode4= new TreeNode(4);
        TreeNode treeNode5= new TreeNode(5);
        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;
        treeNode2.left = treeNode4;
        treeNode2.right = treeNode5;
        return treeNode1;
    }
    // 前序遍历
    public static void preOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        System.out.println(root.val+ " ");
        preOrder(root.left);
        preOrder(root.right);
    }
    // 中序遍历
    public static void inOrder(TreeNode root) {
        if (root == null){
            return;
        }
        inOrder(root.left);
        System.out.println(root.val+" ");
        inOrder(root.right);
    }
    // 后序遍历
    public static void postOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.println(root.val+" ");
    }
}